package com.cy.pj.Controller;

import com.cy.pj.pojo.ResponseReulSet;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.sql.ResultSetMetaData;
import java.util.HashMap;
import java.util.Map;

@Controller
@ResponseBody
public class JisonController {
    @RequestMapping("/doSetGetKey")
    public ResponseReulSet doSetGetKey(){
        ResponseReulSet rps = new ResponseReulSet();
        rps.setCode(200);
        rps.setMsg("李四");
        return rps;
    }
    @RequestMapping("/doPrint")
    public void doPrint(HttpServletResponse response) throws Exception {
        Map<String,Object> map = new HashMap<>();
        map.put("username","李四");
        map.put("state",true);
        ObjectMapper om = new ObjectMapper();
        String jisonStr = om.writeValueAsString(map);
        System.out.println("jisomstr="+jisonStr);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println(jisonStr);
    }
    @RequestMapping("/getHealth")
    public Map<String,Object> doHealth(){
        Map<String,Object> map = new HashMap<>();
        map.put("username","李四");
        map.put("state",true);
        return map;
    }
}
